
package edu.tongji.jiaowu.dao.jdbc;
 
import java.util.List;

import edu.tongji.jiaowu.dao.RestudyStudentDao;
import com.tongji.quickCRUDQ.define.Row;
import com.tongji.quickCRUDQ.model.CommonBean;
import com.tongji.quickCRUDQ.dao.jdbc.BaseDaoJdbc;

public class RestudyStudentDaoJdbc extends BaseDaoJdbc implements RestudyStudentDao {
	String tableName="T_RESTUDY_STUDENT";
	String beanName="restudyStudent";
	
	public CommonBean createRestudyStudent(){
		CommonBean restudyStudents=this.createBean(tableName,beanName);
                return restudyStudents;		
	}
	
/*
	public CommonBean findRestudyStudents(String refid) {
		CommonBean restudyStudents=this.createRestudyStudent();
		String sql="select * from T_RESTUDY_STUDENT where refid=?";
		List data=this.getCommonDao().select(sql,new String[]{refid});
		restudyStudents.addData(data);
                return restudyStudents;
       }
*/
	public CommonBean findRestudyStudentById(String id) {
		CommonBean restudyStudents=this.createRestudyStudent();
		String sql="select * from T_RESTUDY_STUDENT where id=?";
		List data=this.getCommonDao().select(sql,new String[]{id});
		restudyStudents.addData(data);
    return restudyStudents;
  }
  
	public CommonBean findAllRestudyStudents() {
		CommonBean restudyStudents=this.createRestudyStudent();
		String sql="select * from T_RESTUDY_STUDENT ";
		List data=this.getCommonDao().select(sql,new String[]{});
		restudyStudents.addData(data);
    return restudyStudents;
  }
	public void insertRestudyStudent(CommonBean restudyStudentBean){
		List data=restudyStudentBean.getData();
		Row row=this.getRow(tableName);
		this.getCommonDao().templateBatchInsert(row,data,this.getIdGenerator());
	}
	public void updateRestudyStudent(CommonBean restudyStudentBean){
		List data=restudyStudentBean.getData();
		Row row=this.getRow(tableName);
		this.getCommonDao().templateBatchUpdate(row,data);
	}

	public void loadRestudyStudents(String restudyYear, String restudySemester) {
		String delSql="delete from t_restudy_student where school_year=? and school_semester=?";
		String insertSql="INSERT INTO T_RESTUDY_STUDENT(SCHOOL_YEAR,SCHOOL_SEMESTER,ID,STUDY_YEAR,STUDY_SEMESTER,STUDENT_NO,STUDENT_NAME,GRADE,MAJOR,MAJOR_NAME,COURSE_NO,COURSE_NAME,SCORE_NATURE,CREDIT,COURSE_TYPE)\n" +
		"SELECT ?,?,ID,STUDY_YEAR,STUDY_SEMESTER,STUDENT_NO,STUDENT_NAME,GRADE,MAJOR,MAJOR_NAME,COURSE_NO,COURSE_NAME,SCORE_NATURE,CREDIT,COURSE_TYPE\n" + 
		"FROM V_RESTUDY_STUDENT T";
		String[] params=new String[]{restudyYear,restudySemester};
		getCommonDao().updateRecord(delSql, params);
		getCommonDao().updateRecord(insertSql, params);		
	}
}

